#include "transition_map.hpp"

transition_map::transition_map(const transition_map& tm){
  if(this != &tm){
    chan_maps=tm.chan_maps;
  }
}

transition_map& transition_map::operator=(const transition_map& tm){
  if(this != &tm){
    chan_maps=tm.chan_maps;
  }
  return *this;
}

void transition_map::set_map(int i,tmap t){
  //If channel with index ii exists
  if( chan_maps.find(i) != chan_maps.end()){
    chan_maps.erase(i);
    chan_maps.insert(std::make_pair(i,t));
  }
  else{
    chan_maps.insert(std::make_pair(i,t));
  }
}

void transition_map::set_map(tmap t){
  int last=chan_maps.end()->first;
  chan_maps.insert(std::make_pair(last,t));
}

tmap transition_map::operator()(int k){
  std::map<int,tmap>::iterator it;
  it=chan_maps.find(k);
  if(it==chan_maps.end()){
    std::cerr<<"Channel map with key "<<k<<" does not exist!"<<std::endl;
    exit(1);
  }
  return it->second;
}

tmap transition_map::get_map(int k){
  return this->operator()(k);
}
